﻿namespace VisitorsApp
{
    using System;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Navigation;
    using VisitorsApp.ViewModels;
    using VisitorsApp.Views;

    /// <summary>
    /// Home page for the application.
    /// </summary>
    public partial class Home : Page
    {
        private MainViewModel viewModel;

        /// <summary>
        /// Creates a new <see cref="Home"/> instance.
        /// </summary>
        public Home()
        {
            InitializeComponent();
            viewModel = new MainViewModel();
            this.DataContext = viewModel;
            this.Title = ApplicationStrings.HomePageTitle;
        }

        public void ButtonViewDetails_Click(object sender, RoutedEventArgs e)
        {
            PhotoDetails details = new PhotoDetails(this.viewModel);
            
            details.Show();
        }

        /// <summary>
        /// Executes when the user navigates to this page.
        /// </summary>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (!WebContext.Current.User.IsAuthenticated)
            {
                NavigationService.Navigate(new Uri("/Home", UriKind.Relative));
            }
        }
    }
}